home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / gb12345.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  1.3 KB  |  48 lines

  1. /*
  2.  * GB/T 12345-1990
  3.  */
  4.  
  5. /*
  6.  * GB/T 12345-1990 is a traditional chinese counterpart of GB 2312-1986.
  7.  * According to the unicode.org tables:
  8.  * 2146 characters have been changed to their traditional counterpart,
  9.  * 103 characters have been added, no characters have been removed.
  10.  * Therefore we use an auxiliary table, which contains only the changes.
  11.  */
  12.  
  13. #include "gb12345ext.h"
  14.  
  15. static int
  16. gb12345_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  17. {
  18.   int ret;
  19.  
  20.   /* The gb12345ext table overrides some entries in the gb2312 table. */
  21.   /* Try the GB12345 extensions -> Unicode table. */
  22.   ret = gb12345ext_mbtowc(conv,pwc,s,n);
  23.   if (ret != RET_ILSEQ)
  24.     return ret;
  25.   /* Try the GB2312 -> Unicode table. */
  26.   ret = gb2312_mbtowc(conv,pwc,s,n);
  27.   return ret;
  28. }
  29.  
  30. static int
  31. gb12345_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  32. {
  33.   int ret;
  34.  
  35.   /* The gb12345ext table overrides some entries in the gb2312 table. */
  36.   /* Try the Unicode -> GB12345 extensions table. */
  37.   ret = gb12345ext_wctomb(conv,r,wc,n);
  38.   if (ret != RET_ILSEQ)
  39.     return ret;
  40.   /* Try the Unicode -> GB2312 table, and check that the resulting GB2312
  41.      byte sequence is not overridden by the GB12345 extensions table. */
  42.   ret = gb2312_wctomb(conv,r,wc,n);
  43.   if (ret == 2 && gb12345ext_mbtowc(conv,&wc,r,2) == 2)
  44.     return RET_ILSEQ;
  45.   else
  46.     return ret;
  47. }
  48.